
export interface OnFulfilledFn<V> {
    (value: V): V | Promise<V>
}
export interface OnRejectedFn {
    (error: any): any
}
export interface Interceptor<V=any> {
    onFulfilled: OnFulfilledFn<V>
    onRejected?: OnRejectedFn
}
// T可能是AxiosRequestConfig 也有可能是AxiosResponse
export default class InterceptorManager<V>{
    public interceptors: Array<Interceptor<V> | null>  = [];
    use(onFulfilled: OnFulfilledFn<V>, onRejected?: OnRejectedFn): number {
        this.interceptors.push({
            onFulfilled,
            onRejected
        })
        return this.interceptors.length - 1
    }
    eject(id: number): void {
        if (this.interceptors[id]) {
            this.interceptors[id] = null
        }
    }
}